package com.model.dao;

// default package
// Generated Feb 7, 2014 12:22:36 PM by Hibernate Tools 3.4.0.CR1

import javax.ejb.Stateless;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 * Home object for domain model class GuestTable.
 * 
 * @see .GuestTable
 * @author Hibernate Tools
 */
@Stateless
public class GuestTableDAO {

	private static final Log log = LogFactory.getLog(GuestTableDAO.class);

	Session session;
	Transaction tx;

	public Integer persist(GuestTable transientInstance) throws Exception {
		log.debug("persisting GuestTable instance");
		try {
			session = SessionFactoryUtil.getSessionFactory()
					.getCurrentSession();
			tx = session.beginTransaction();
			Integer userId = (Integer) session.save(transientInstance);
			tx.commit();
			log.debug("persist successful");
			return userId;
		} catch (RuntimeException re) {
			session.close();
			if (tx != null) {
				tx.rollback();
			}
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(GuestTable persistentInstance) throws Exception {
		log.debug("removing GuestTable instance");
		try {
			session = SessionFactoryUtil.getSessionFactory()
					.getCurrentSession();
			tx = session.beginTransaction();
			session.delete(persistentInstance);
			tx.commit();
			log.debug("remove successful");
		} catch (Exception ex) {
			session.close();
			if (tx != null) {
				tx.rollback();
			}
			log.error("remove failed", ex);
			throw ex;
		}
	}

	public GuestTable merge(GuestTable detachedInstance) throws Exception {
		log.debug("merging GuestTable instance");
		try {
			session = SessionFactoryUtil.getSessionFactory()
					.getCurrentSession();
			tx = session.beginTransaction();
			GuestTable result = (GuestTable) session.merge(detachedInstance);
			tx.commit();
			log.debug("merge successful");
			return result;
		} catch (Exception ex) {
			session.close();
			if (tx != null) {
				tx.rollback();
			}
			log.error("merge failed", ex);
			throw ex;
		}
	}

	public GuestTable findById(Integer id) throws Exception {
		log.debug("getting GuestTable instance with id: " + id);
		try {
			session = SessionFactoryUtil.getSessionFactory()
					.getCurrentSession();
			tx = session.beginTransaction();
			GuestTable instance = (GuestTable) session.get(GuestTable.class, id);
			tx.commit();
			log.debug("get successful");
			return instance;
		} catch (Exception ex) {
			session.close();
			if (tx != null) {
				tx.rollback();
			}
			log.error("get failed", ex);
			throw ex;
		}
	}
}
